package com.ruoyi.web.controller.shop.goods;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.shop.common.constant.ShopConstants;
import com.ruoyi.shop.goods.domain.ShopGoodsEvaluate;
import com.ruoyi.shop.goods.service.IShopGoodsEvaluateService;
import com.ruoyi.shop.goods.vo.ShopGoodsEvaluateVo;

/**
 * 商品评论Controller
 * 
 * |----------------------------------------------------------------------|
 * |favorshop [简单好用，让您喜爱的小商城]
 * |----------------------------------------------------------------------|
 * |copyright www.favorshop.cn All rights reserved.
 * |----------------------------------------------------------------------|
 * | @author xuxiang
 * |----------------------------------------------------------------------|
 * | @date 2023-05-29
 * |----------------------------------------------------------------------|
 */
@Controller
@RequestMapping("/shop/goods/evaluate")
public class ShopGoodsEvaluateController extends BaseController {
	private String prefix = "shop/goods/evaluate";

	@Autowired
	private IShopGoodsEvaluateService shopGoodsEvaluateService;

	@RequiresPermissions("goods:evaluate:view")
	@GetMapping()
	public String evaluate() {
		return prefix + "/evaluate";
	}

	/**
	 * 评价详情页
	 * 
	 * @param evaluateId
	 * @param mmap
	 * @return
	 */
	@RequiresPermissions("shop:evaluate:detail")
	@GetMapping("/detail/{evaluateId}")
	public String detail(@PathVariable("evaluateId") Long evaluateId, ModelMap mmap) {
		ShopGoodsEvaluateVo evaluate = shopGoodsEvaluateService.selectEvaluateById(evaluateId);
		evaluate.setImageArr(Convert.toStrArray(evaluate.getImages()));
		mmap.put("evaluate", evaluate);
		return prefix + "/detail";
	}

	/**
	 * 查询商品评论列表
	 */
	@RequiresPermissions("goods:evaluate:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ShopGoodsEvaluateVo params) {
		startPage();
		List<ShopGoodsEvaluateVo> list = shopGoodsEvaluateService.selectEvaluateList(params);
		return getDataTable(list);
	}

	/**
	 * 改变评论显示状态
	 * 
	 * @param params
	 * @return
	 */
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(ShopGoodsEvaluate params) {
		return toAjax(shopGoodsEvaluateService.changeStatus(params));
	}

	/**
	 * 回复内容
	 * 
	 * @param goodsEvaluate
	 * @return
	 */
	@PostMapping("/replay")
	@ResponseBody
	public AjaxResult replay(ShopGoodsEvaluate params) {
		params.setReplyStatus(ShopConstants.YES);// 已回复
		return toAjax(shopGoodsEvaluateService.updateGoodsEvaluate(params));
	}

}
